package com.app.qbake.module.square.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.hannesdorfmann.adapterdelegates3.AdapterDelegate;
import com.wind.base.adapter.DisplayItem;
import com.wind.data.square.bean.BannerItem;
import com.wind.data.square.bean.BannerList;
import com.app.qbake.R;
import com.wind.view.CarouselViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wind on 2018/9/6.
 */

public class BannerDelegate extends AdapterDelegate<List<DisplayItem>> {
    private Activity mActivity;
    public BannerDelegate(Activity activity){
        this.mActivity=activity;
    }
    @Override
    protected boolean isForViewType(@NonNull List<DisplayItem> items, int position) {
        return items.get(position) instanceof BannerList;
    }

    @NonNull
    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
        View view=mActivity.getLayoutInflater().inflate(R.layout.item_banner,parent,false);
        return new ViewHolder(view);

    }

    @Override
    protected void onBindViewHolder(@NonNull List<DisplayItem> items, int position, @NonNull RecyclerView.ViewHolder holder, @NonNull List<Object> payloads) {
        ViewHolder vh= (ViewHolder) holder;
        BannerList banner= (BannerList) items.get(position);
        List<String> picUrl=new ArrayList<>();
        for (BannerItem item:banner.getBanner()){
            picUrl.add(item.getPic_url());
        }
        vh.cvp.setImageResPaths(picUrl);
    }

    private static class ViewHolder extends RecyclerView.ViewHolder{

        CarouselViewPager cvp;
        public ViewHolder(View itemView) {
            super(itemView);
            cvp=itemView.findViewById(R.id.cvp);
        }
    }
}
